<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!doctype html>
<html>
<head>
<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
}
</style>
</head>
<body class="gray-bg">

	<!-- 隐藏域 -->
	<input type="hidden" value="${replaceId}" id="replaceId"
		name="replaceId" />
	<input type="hidden" value="${busiId}" id="busiId" name="busiId" />
	<input type="hidden" value="${modeId}" id="modeId" name="modeId" />
	<input type="hidden" id="dkId" />
	<input type="hidden" id="bbusiId" />
	<input type="hidden" id="dkSubId"/>
	<!-- 隐藏域 -->

	<div class="container creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;垫款调整B</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="buttonfixed" style="display: none;" id="buttonfixed">
			<button type="button" id="save" style="display: none;"
				class="btn dpbtn_blue" onclick="saveOrUpdate();">保存提交</button>
			<button type="button" id="update" style="display: none;"
				class="btn dpbtn_blue" onclick="saveOrUpdate();">修改</button>
		</div>
		<div class="ibox-content ibox-con">
			<%@include file="/jsp/common_yw_include.jsp"%>
			<div class="business-manwife">业务进程</div>
			<div class="business-padding" id="">
				<table class="yw-course">
					<thead>
						<tr>
							<th id="added_status1" equal="0" class="splztab bg-grey">按揭日报表</th>
							<th id="dianzi" equal="30" class="splztab bg-grey">申请垫资
								</li>
							<th id="M_cwshy" equal="50" class="splztab bg-grey">财务审核1</th>
							<th id="M_cwshe" equal="200" class="splztab bg-grey">财务审核2</th>
							<th id="caiwudiankuan" class="splztab bg-grey">财务垫款</th>
							<th id="" class="splztab bg-grey">垫款调整A</th>
							<th id="" class="splztab bg-green">申请垫款调整Ｂ</th>
							<th id="" class="splztab">垫款调整Ｂ审核</th>
							<th id="" class="splztab">垫款调整Ｂ</th>
							<th id="" class="splztab">财务退款</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>

		<div class="business-manwife">车辆信息</div>
		<div class="tche-padding tancQa">
			<table cellpadding="0" cellspacing="0" border="0" class="infor-table"
				id="used-car">
				<tr>
					<td align="right"><label class="control-label np">车辆性质：</label></td>
					<td><mytag:selectTag id="carType" name="carType"
							others="class='select-control' required='required' disabled='disabled'"
							map="${carType }" selected="${ywBusinessCar.carType }" /></td>
					<td align="right" style="display: none;"><label
						class="control-label np">启用日期：</label></td>
					<td style="display: none;"><input id="startDate"
						name="startDate" readonly="readonly" type="text"
						class="select-control"
						value='<fmt:formatDate value="${ywBusinessCar.startDate }" pattern="yyyy-MM-dd"/>' /></td>
				</tr>
			</table>
		</div>
		<!-- 车贷信息 -->
		<%@include file="/web/system/yw/loan_include.jsp"%>
		<form class="form-horizontal buyinfor-form" id="commentForm">
			<div class="business-manwife">垫款调整信息</div>
			<div class="tche-padding">
				<table cellpadding="0" cellspacing="0" border="0"
					class="thead-tabletz">
					<thead class="thead-a">
						<tr>
							<th></th>
							<th>原值</th>
							<th>新值</th>
							<th>调整值</th>
						</tr>
					</thead>
					<tbody class="tbody-a">
						<tr>
							<td>签约贷款额</td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="signLoanAmountOld" name="signLoanAmountOld"
								value="${ywBusiness.signLoanAmount}" /></td>
							<td><input onkeyup="counta();" class="tbody-control" readonly="readonly"
								type="number" id="signLoanAmountNew" name="signLoanAmountNew" /></td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="signLoanAmountAdjust"
								name="signLoanAmountAdjust" /></td>
						</tr>
						<tr>
							<td>实际贷款额</td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="loanAmountOld" name="loanAmountOld"
								value="${ywBusiness.realLoanAmount }" /></td>
							<td><input onkeyup="countb();" class="tbody-control" readonly="readonly"
								type="number" id="loanAmountNew" name="loanAmountNew" /></td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="loanAmountAdjust" name="loanAmountAdjust" /></td>
						</tr>
						<tr>
							<td>经销商返利</td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="rebateDealerOld" name="rebateDealerOld"
								value="${ywFees.rebateDealer}" /></td>
							<td><input onkeyup="countc();" class="tbody-control"
								type="number" id="rebateDealerNew" name="rebateDealerNew" required="required" placeholder="(必填)" /></td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="rebateDealerAdjust" name="rebateDealerAdjust" /></td>
						</tr>
						<tr>
							<td>分公司展业费</td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="rebateProvinceOld" name="rebateProvinceOld"
								value="${ywFees.rebateProvince}" /></td>
							<td><input onkeyup="countd();" class="tbody-control"
								type="number" id="rebateProvinceNew" name="rebateProvinceNew" required="required" placeholder="(必填)" /></td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="rebateProvinceAdjust"
								name="rebateProvinceAdjust" /></td>
						</tr>
						<tr>
							<td>区域&业务员展业费</td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="rebateAreaOld" name="rebateAreaOld"
								value="${ywFees.rebateArea}" /></td>
							<td><input onkeyup="counte();" class="tbody-control"
								type="number" id="rebateAreaNew" name="rebateAreaNew" required="required" placeholder="(必填)" /></td>
							<td><input class="tbody-control" readonly="readonly"
								type="number" id="rebateAreaAdjust" name="rebateAreaAdjust" /></td>
						</tr>

					</tbody>
				</table>
			</div>
		</form>
		<div class="business-manwife">车贷信息</div>
		<div class="tche-padding">
			<ul class="zxsearch-ulsd" style="margin-top: 15px;">
				<li class="zxsearch-ulli">信息备注：</li>
				<li class="zxsearch-ullib"><textarea id="remark" name="remark"
						rows="" cols="" class="form-control"></textarea></li>
			</ul>
		</div>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>
	<!-- layerDate plugin javascript -->
	<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>

	<!-- 车贷信息 -->
	<%@include file="/web/system/yw/loan_js_include.jsp"%>
	<!-- 验证  -->
	<!-- summernote -->
	<%@include file="/js/common-dpqc/dpqc-summernote/comm_summernote_include.jsp"%>
	<!-- 
 	    作者：程立勇
 	   描述：js脚本
 	 -->
	<script type="text/javascript">
	 	$(function(){
	 		$('#carPrice').removeAttr('readonly');
	 		 //判断二手车显示估价
	        $("#carType").change(function(){
	        	changeCarType();
	        });
	        $('#saveLoan').click(function(){
	       		saveLoanB();
	        });
	        
	        $("#loanType").attr("disabled","disabled");
	        
	        $("#ccol2").attr("readonly","readonly");
	        
	        $(".noneStyle").hide();
	        
	        xitongguJia();  
	 		getData();
	 		getDataInfoByBusiId();
	 	});
	 	
	 	function changeCarType(){
	 		countLoanMonth();
        	adapterCarType();
        	
	 	}
	 	
	 	/* 弹窗嵌套估价 */
	 	function xitongguJia(){
	 		$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
	 			data:{"parentValue":"Website_Usedcar"},
	 			success: function(datas){
 					  var result = datas.result.rows;
 					  var content="";
 					  for(var i=0; i<result.length;i++){
 						  var href = result[i].remarks;
 						  var name = result[i].name;
 						  content +='<div class="gujiamenu btn dpbtn_green" onclick="layeropen(\''+href+'\')">'+name+'</div>';
 					  }
 					 $("#xitongGj").append(content);
	              }
		   });
	 	}
	 	
	 	function layeropen(href){
	 	   layer.open({
			  type: 2,
			  area: ['80%', '80%'], //宽高
			  content:href,
			});
	 	} 
	 	
	 	$(function(){
	        $("#commentForm").validate({
	        	 rules: {
	        		 signLoanAmountNew:{
	        			 allMoney:true
	        		 },
	        		 loanAmountNew:{
	        			 allMoney:true
	        		 },
	        		 rebateDealerNew:{
	        			 allMoney:true
	        		 },
	        		 rebateAreaNew:{
	        			 allMoney:true
	        		 }
	        	 },
			    //重写showErrors
		        showErrors: function (errorMap, errorList) {
		        	$.each(errorList, function (i, v) {
		        		layer.tips(v.message, v.element, { time: 1500 });
		        		
		                return false;
		            });
		        },
		        /* 失去焦点时验证 */
		        onfocusout: function(element) {$(element).valid(); },
		        /*  键盘抬起不验证 */
		        onkeyup:false,
		    });
	        
	        $("#commentFormd").validate({
		        rules: {
		        	carAge:{
		        		min:0
		        	},
		        	carEstimatePrice:{
		        		min:1
		        	},
		        	bankRate:{
		        		min:0
		        	},
		        	loanAmount:{
		        		min:0
		        	},
		        	companyRate:{
		        		min:0
		        	},
		        	carPrice:{
		        		allMoney:true
		        	},
		        	loanAmount:{
		        		allMoney:true
		        	},
		        },
		        messages: {
		        	carAge:{
		        		min:"请输入不能小于0的值"
		        	},
		        	carEstimatePrice:{
		        		min:"请输入不能小于0的值"
		        	},
		        	bankRate:{
		        		min:"请输入不能小于0的值"
		        	},
		        	loanAmount:{
		        		min:"请输入不能小于0的值"
		        	},
		        	companyRate:{
		        		min:"请输入不能小于0的值"
		        	}
		        },
		        //重写showErrors
		        showErrors: function (errorMap, errorList) {
		            $.each(errorList, function (i, v) {
		            	 layer.tips(v.message, v.element, { time: 1500 });
		                 
		                return false;
		            });  
		        },
		        /* 失去焦点时验证 */
		        onfocusout: function(element) {$(element).valid(); },
		        /*  键盘抬起不验证 */
		        onkeyup:false,
		    });
		});
	 	
	 	
	 	
		function adapterCarType(){
		    warning();
        	if($("#carType").val() == '02') {
        		$('.usedCar').show();
        		$('#carAge').attr('required','');
        		$('#carEstimatePrice').attr('required','');
        	} else {
        		$('.usedCar').hide();
        		$('#carAge').removeAttr('required');
        		$('#carEstimatePrice').removeAttr('required');
        	}
        }
		
	 	 var getData=function(){
	 	    	var data={};
	 	 		data.id=$.getUrlData("id");
	 	 		$.dpAjax({
	 	    		url:'${basePath}/YwBusinessLoanController/getMultiById',
	 	    		data:data,
	 				success: function(datas){
	 					 saveIndex = 0;
	    				 var ywBusinessCar = datas.result.ywBusinessCar;
	     				 if(ywBusinessCar) {
	     					$('#carId').val(ywBusinessCar.replaceId);
							var price = ywBusinessCar.price ? ywBusinessCar.price.toFixed(2) : '';
							$('#carPrice').val(price);
	     				 }
	     				//车贷信息
	    					var ywBusinessLoan = datas.result.ywBusinessLoan;
	    					if(ywBusinessLoan) {
	    						showLoanDataB(ywBusinessLoan);
	    					} else {
	    						$('#loanBank').val('ICBC');
	    						showLoan();
	    						$('#loanType').val('04');
	    						showType();
	    					}
    		 			
    					//贷款银行
	     				 var loanBanks = datas.result.loanBanks;
	     				 if(loanBanks) {
	     					 var html = '';
	     					 for(var i in loanBanks) {
	     						 var loanBank = loanBanks[i];
	     						 html += '<option value="'+loanBank.value +'">' + loanBank.name +'</option>';
	     						$('#loanBank').html(html);
	     						 if(loanBank.value==datas.result.ywBusinessLoan.loanBank){
	     							$('#loanBank').val(loanBank.value);
	     						 }
	     					 }
	     				 } else {
	     					 $('#loanBank').html('<option value="">--没有配置贷款银行--</option>');
	     				 }
	     				 
	     				//取整模式
	     				 var intTypes = datas.result.intTypes;
	     				 if(intTypes) {
	     					 var html = '';
	     					 for(var i in intTypes) {
	     						 var intType = intTypes[i];
	     						 html += '<option value="' + intType.value +'">'+intType.name +'</option>';
	     					 }
	     					$('#ccol1').html(html);
	     				 } else {
	     					 $('#ccol1').html('<option value="">--没有配置取整模式--</option>');
	     				 }
	     				 
	     				
    					
	     				changeCarType();
	 	            }
	 	    	});
	 	    }
	 	function showWarningUsedIcbc(){
	 		$('#zhkcj_show').text('已＞80% 建议调整');
	 		$('#qyhkcj_show').text('已＞70% 建议调整');
	 	}
	 	function showWarningNewIcbc(){
	 		$('#zhkcj_show').text('已＞90% 建议调整');
	 		$('#qyhkcj_show').text('已＞80% 建议调整');
	 	}
	 	function showWarningUsedBoc(){
	 		$('#zhkcj_show').text('已＞70% 建议调整');
	 		$('#qyhkcj_show').text('已＞70% 建议调整');
	 	}
	 	
	 	var getDataInfoByBusiId=function(){
	 		var data={};
	 		data.busiId=$.getUrlData("id");
	 		$.dpAjax({
	    		url:'${basePath}/CwRemitAdjustbSubController/list',
	    		data:data,
					success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  saveIndex = 0;
	    				  if(datas.result.rows.length>0){
	    					  var data=datas.result.rows[0];
	    					  $("#bbusiId").val(data.busiId);
	    					  $("#dkId").val(data.remitAdjustbId);
	    					  $("#dkSubId").val(data.replaceId);
	    					  $("#remark").val(data.remarks);
	    					  $("#update").show();
	    					  $("#buttonfixed").show();
	    					  $("#save").hide();
	    					  $("#signLoanAmountOld").val(data.signLoanAmountOld);
	    					  $("#loanAmountOld").val(data.loanAmountOld);
	    					  $("#signLoanAmountNew").val(data.signLoanAmountNew);
	    					  $("#loanAmountNew").val(data.loanAmountNew);
	    					  $("#signLoanAmountAdjust").val(parseFloat(data.signLoanAmountNew)-parseFloat(data.signLoanAmountOld));
	    					  $("#loanAmountAdjust").val(parseFloat(data.loanAmountNew)-parseFloat(data.loanAmountOld));
	    					  $("#rebateDealerNew").val(data.rebateDealerNew);
	    					  $("#rebateProvinceNew").val(data.rebateProvinceNew);
	    					  $("#rebateAreaNew").val(data.rebateAreaNew);
	    					  $("#rebateAreaAdjust").val(parseFloat(data.rebateAreaNew)-parseFloat(data.rebateAreaOld));
	    					  $("#rebateProvinceAdjust").val(parseFloat(data.rebateProvinceNew)-parseFloat(data.rebateProvinceOld));
	    					  $("#rebateDealerAdjust").val(parseFloat(data.rebateDealerNew)-parseFloat(data.rebateDealerOld));
	    				  }else{
	    					  $("#buttonfixed").show();
	    					  $("#save").show();
	    					  $("#update").hide();
	    				  }
	    				  layer.msg('执行成功！', {icon: 6});
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
	            }
	    	});
	 	}
 	//增加变量值
	var saveIndex = 0;	
 	   
 	var saveOrUpdate=function(){
 		var data={};
 		var dkId=$("#dkId").val();
 		var url='${basePath}/CwRemitAdjustBController/insert';
 		if(dkId!=""){
 			data.id=dkId;
 			data.remitAdjustbId=$("#dkSubId").val();
 			url='${basePath}/CwRemitAdjustBController/update';
 		}
 		
 		data.busiId=$.getUrlData("id");
 		data.signLoanAmountOld=$("#signLoanAmountOld").val();
 		data.signLoanAmountNew=$("#signLoanAmountNew").val();
 		data.signLoanAmountAdjust=$("#signLoanAmountAdjust").val();
 		data.loanAmountOld=$("#loanAmountOld").val();
 		data.loanAmountNew=$("#loanAmountNew").val();
 		data.loanAmountAdjust=$("#loanAmountAdjust").val();
 		data.rebateDealerOld=$("#rebateDealerOld").val();
 		data.rebateDealerNew=$("#rebateDealerNew").val();
 		data.rebateDealerAdjust=$("#rebateDealerAdjust").val();
 		data.rebateProvinceOld=$("#rebateProvinceOld").val();
 		data.rebateProvinceNew=$("#rebateProvinceNew").val();
 		data.rebateProvinceAdjust=$("#rebateProvinceAdjust").val();
 		data.rebateAreaOld=$("#rebateAreaOld").val();
 		data.rebateAreaNew=$("#rebateAreaNew").val();
 		data.rebateAreaAdjust=$("#rebateAreaAdjust").val();
 		data.cusId=$("#customerId").val();
 		data.remarks=$("#remark").val();
		
		data.carPriceNew=$("#carPrice").val();
		data.loanMonthNew=$("#loanMonth").val()==""?0:$("#loanMonth").val();
		data.amountMonthlyNew=$("#amountMonthly").val()==""?0:$("#amountMonthly").val();
		data.totalRepaymentAmountNew=$("#totalRepaymentAmount").val()==""?0:$("#totalRepaymentAmount").val();
		data.totalRepaymentProportionNew=$("#qyhkcj").val();
		data.monthlyPrincipalAmountNew=$("#monthlyPrincipalAmount").val()==""?0:$("#monthlyPrincipalAmount").val();
		data.monthlyFeeNew=$("#monthlyFee").val()==""?0:$("#monthlyFee").val();
		data.firstMonthAmountNew=$("#firstMonthAmount").val()==""?0:$("#firstMonthAmount").val();
		data.firstMonthFeeNew=$("#firstMonthFee").val()==""?0:$("#firstMonthFee").val();
		data.firstMonthTotalAmountNew=$("#firstMonthTotalAmount").val()==""?0:$("#firstMonthTotalAmount").val();
		data.firstPaymentAmount=$("#firstPaymentAmount").val();
		data.carId=$("#zzj_carId").val();
		data.carEstimatePriceNew=$("#carEstimatePrice").val()==""?0:$("#carEstimatePrice").val();
		data.servicePriceNew=$("#servicePrice").val()==""?0:$("#servicePrice").val()
		var validstatus = $("#commentForm").valid();
		if(validstatus){
			if(saveIndex == 1)
 			{
 				layer.msg("垫款调整B申请正在提交数据，不可重复操作！", {icon: 5});
 				return;
 			}
 	 		//改变变量的值
 			saveIndex = 1;
	 		$.dpAjax({
	    		url:url,
	    		data:data,
					success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  saveIndex = 1;
	    				  window.location.href="${basePath}/web/caiWuXiangGuan/diankuanZBList.jsp";
	    					return ;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
	            }
	    	});
		}else{
			layer.msg('有验证未通过，请仔细检查！', {icon: 5});
		}
 	}
	</script>
</body>
</html>
